<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        table {
            width: 500px;
            margin: 200px 200px;
            border-collapse: collapse;
            border: 1px solid #333;
            text-align: center;
        }
        td,
        th {
            border: 1px solid #333;
        }
        thead tr{
            height: 40px;
            background-color:#ccc;
        }
    </style>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

    <script>
        //准备几个数据
        var datas = [
        {
            name:'小明',
            subject:'JS',
            score:100
        },
        {
            name:'张二麻子',
            subject:'HTML',
            score:95
        },
        {
            name:'王铎多',
            subject:'CSS',
            score:70
        },
        {
            name:'大猪蹄子',
            subject:'???',
            score:0
        }
        ];

        //数据的个数
        var num = datas.length;
        var tbody = document.querySelector('tbody');
        console.log(tbody);
        
        for(var i =0;i<num;i++){
            //创建tr
            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            //行里面创建td
            for(var k in datas[i]){
                var td = document.createElement('td');
                //创建单元格的同时，把属性值填入
                td.innerHTML=datas[i][k];
                tr.appendChild(td);
            }
            var td = document.createElement('td');
            td.innerHTML = "<a href = 'javascript:;'>删除</a>";
            tr.appendChild(td);
        }
        //添加删除操作
        var as = document.querySelectorAll('a');
        for (var i=0;i<as.length;i++){
            as[i].onclick=function(){
                //点击a 删除a当前所在的行
                tbody.removeChild(this.parentNode.parentNode);
            }
        }
    </script>
</body>
</html>